/*
 * tester.m
 *
 * This file is part of the MPInteger library
 * Distributed under the GNU General Public License
 *
 * Written by Bill Garrison
 * Last changed 2008 Oct 09
 *
 * This file is used to test some various aspects of the MPInteger library.
 */

#import <stdio.h>
#import <objc/Object.h>
#import "MPInteger/MPInteger.h"

int main( int argc, const char *argv[] )
{
  printf( "ARITHMETIC:\n" );
  
  MPMutableInteger * int1 = [[MPMutableInteger alloc] initWithString: "123456789123456789"];
  MPMutableInteger * int2 = [[MPMutableInteger alloc] initWithUnsignedInt: 15];
  
  printf( "%s - %d = ", [int1 stringValue], [int2 intValue] );
  [int1 subtractMPInteger: int2];
  printf( "%s\n", [int1 stringValue] );
  
  printf( "%s + %d = ", [int1 stringValue], 4 );
  [int1 addUnsignedInt: 4];
  printf( "%s\n", [int1 stringValue] );
  
  MPMutableInteger * int3 = [int1 mpIntegerByMultiplyingMPInteger: int2];
  printf( "%s * %s = %s\n\n", [int1 stringValue], [int2 stringValue], [int3 stringValue] );
  [int1 free];
  [int2 free];
  [int3 free];
  
  printf( "DIVISION:\n" );
  
  int1 = [[MPMutableInteger alloc] initWithString: "123456789123456789"];
  int2 = [[MPMutableInteger alloc] initWithUnsignedInt: 15];
  
  if( [int1 isDivisibleByMPInteger: int2] )
    printf( "divisible / " );
  else
    printf( "not divisible / " );
  if( [int1 isDivisibleByUnsignedInt: 15] )
    printf( "divisible\n" );
  else
    printf( "not divisible\n" );  
  
  printf( "%s / %s = ", [int1 stringValue], [int2 stringValue] );
  [int1 divideMPInteger: int2];
  printf( "%s\n", [int1 stringValue] );
  
  int3 = [[MPMutableInteger alloc] init];
  int3 = [int1 mpIntegerByModuloUnsignedInt: 10];
  printf( "%s %% %d = %s\n\n", [int1 stringValue], 10, [int3 stringValue] );
  
  [int1 free];
  [int2 free];
  [int3 free];
  
  printf( "EXPONENTIATION:\n" );
  
  int1 = [[MPMutableInteger alloc] initWithString: "123456789123456789"];
  
  printf( "%s ^ %d = ", [int1 stringValue], 5 );
  [int1 raiseToExponentUnsignedInt: 5];
  printf( "%s\n", [int1 stringValue] );
  
  [int1 setWithString: "123456789123456789"];
  int3 = [int1 mpIntegerByRaisingToExponentUnsignedInt: 10];
  printf( "%s ^ %d = %s\n\n", [int1 stringValue], 10, [int3 stringValue] );
  
  [int1 free];
  [int3 free];
  
  printf( "COMPARISON:\n" );
  
  int1 = [MPMutableInteger mpIntegerWithString: "55667788"];
  int2 = [int1 mpIntegerByRaisingToExponentUnsignedInt: 12234423
                                          modMPInteger: [MPInteger mpIntegerWithString: "1000"]];
  printf( "%s %s %d\n", [int2 stringValue], [int2 compare: int1]==BGOrderedAscending?"<":">=", [int1 unsignedIntValue] );
  printf( "%s %s %d\n", [int1 stringValue], [int1 compare: int2]==BGOrderedAscending?"<":">=", [int2 unsignedIntValue] );
  printf( "%s %s %d\n", [int1 stringValue], [int1 isEqualToMPInteger: int2]?"==":"!=", [int2 unsignedIntValue] );
  printf( "%s %s %d\n", [int2 stringValue], [int2 compare: int1]==BGOrderedDescending?">":"<=", [int1 unsignedIntValue] );
  printf( "%s %s %d\n", [int1 stringValue], [int1 compare: int2]==BGOrderedDescending?">":"<=", [int2 unsignedIntValue] );
  
  [int1 free];
  [int2 free];
  
  return 0;
}
